class MyPromise {
  constructor(executor) {
    this.initValue();
    this.initBind();
    try {
      executor(this.resolve, this.reject);
    } catch (e) {
      this.reject(e);
    }
  }
  initBind() {
    this.resolve = this.resolve.bind(this);
    this.reject = this.reject.bind(this);
  }
  initValue() {
    this.PromiseResult = null;
    this.PromiseState = "pending";
  }
  resolve(value) {
    if (this.PromiseState !== "pending") return;
    this.PromiseResult = value;
    this.PromiseState = "resolve";
  }
  reject(reason) {
    if (this.PromiseState !== "pending") return;
    this.PromiseResult = reason;
    this.PromiseState = "reject";
  }
  then() {
    this.resultThen();
  }
  resultThen(res) {
    res = this.PromiseResult;
    return res;
  }
}

const promise = new MyPromise((resolve, reject) => {
  resolve(111);
  reject(222);
});
console.log(promise);
